﻿package ui {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.KeyboardEvent;
	import flash.text.AntiAliasType;
	import flash.text.GridFitType;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.ui.Keyboard;
	public class TextLabel extends UIItem {
		private var labelTxt:TextField = new TextField();
		private static const LABEL_WIDTH:Number = NaN;
		
		public var w:Number = NaN;
		public var h:Number = NaN;
		public var color:int = 0x000000;
		
		/**
		 * 
		 * @param	labelText
		 * @param	defaultText
		 * @param	w	Input Width
		 */
		public function TextLabel(labelText:String, options:Object = null) {
			applyOptions(options);
			
			labelTxt.defaultTextFormat = new TextFormat("Tahoma", 9, color);
			labelTxt.text = labelText;
			labelTxt.antiAliasType = AntiAliasType.ADVANCED;
			labelTxt.gridFitType = GridFitType.PIXEL;
			if (isNaN(w) && isNaN(h)) {
				labelTxt.autoSize = TextFieldAutoSize.LEFT;
			} else {
				if (isNaN(h)) {
					labelTxt.autoSize = TextFieldAutoSize.LEFT;
					var lh:Number = labelTxt.height;
					labelTxt.autoSize = TextFieldAutoSize.NONE;
					labelTxt.height = lh;
				} else {
					labelTxt.height = h;
				}
				if (!isNaN(w)) labelTxt.width = w;
			}
			labelTxt.selectable = labelTxt.tabEnabled = labelTxt.mouseEnabled = false;
			mouseEnabled = mouseChildren = false;
			addChild(labelTxt);
			
			labelTxt.y = gridHeight/2-labelTxt.height/2-2;
		}
		public function get text():String {
			return labelTxt.text;
		}
		public function set text(v:String):void {
			labelTxt.text = v;
		}
	}
}